<?php defined('BASEPATH') OR exit('No direct script access allowed');


class Role_model extends Base_model
{
	protected $_table_name = 'role';
    protected $_key_name = 'id';
	
	public function __construct()
    {
        parent::__construct();
		
    }

    public function saves($data_arr = NULL)
    {
        if($data_arr == NULL) return false;

        $data_arr["ctime"] = time();
        return $this->replace($data_arr);
    }

    public function adds($data_arr = NULL)
    {
        if($data_arr == NULL) return false;

        $data_arr["ctime"] = time();
        return $this->insert($data_arr);
    }

    public function edits($id = 0,$data_arr = NULL)
    {
        if($id <= 0 || $data_arr == NULL) return false;
        $this->where($this->_key_name,$id);
        $data_arr["etime"] = time();
        return $this->update($data_arr);
    }

    public function dels($ids_arr = NULL)
    {
        if($ids_arr == NULL) return false;
        $this->where_in($this->_key_name,$ids_arr);
        $data_arr['dtime'] = time();
        return $this->update($data_arr);
    }

    public function info($id = 0)
    {
        if($id == NULL) return NULL;
        $this->select("id,name,remark,isroot");
        $this->where($this->_key_name,$id);
        $this->where('dtime',0);
        return $this->row();
    }

    public function alls()
    {
        $this->select("id,name,remark,isroot,create_by as createBy,ctime as createTime");
        $this->where('dtime',0);
        return $this->all();
    }

    public function lists($limit = NULL,$map_arr = NULL)
    {
        $this->select("id,name,remark,isroot,create_by as createBy,ctime as createTime");
        //print_r($map_arr);
        if($map_arr["name"])
        {
            $this->where("name",$map_arr["name"]);
        }
        $this->where('dtime',0);
        if($this->set_limit($limit))
        {
            return $this->result_rows();
        }
        else
        {
            return $this->result();
        }

    }
	
}
/* End of file base_model.php */
/* Location: ./system/application/models/base_model.php */
